package lesson14.protobuf;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.codec.protobuf.*;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * websock 长连接<br/>
 * Created on : 2018-01-29 23:12
 * @author lizebin
 */
public class ServerInitializer extends ChannelInitializer<NioSocketChannel> {

	@Override
	protected void initChannel(NioSocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();

		//声明数据类型
		pipeline.addLast(new ProtobufDecoder(Sinoxk.Message.getDefaultInstance()));
		pipeline.addLast(new ProtobufEncoder());
		pipeline.addLast(new ProtobufVarint32FrameDecoder());
		pipeline.addLast(new ProtobufVarint32LengthFieldPrepender());

		pipeline.addLast(new ServerHandler());
	}

}
